package com.longcai.controller.messagepush;


import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.longcai.advice.RollBackExecption;
import com.longcai.bean.ApiResult;
import com.longcai.bean.PageHelper;
import com.longcai.entity.messagepush.ClyjMessagePush;
import com.longcai.entity.messagepush.ClyjMessagePushFormwordDesc;
import com.longcai.page.table.PageTableResponse;
import com.longcai.service.messagepush.ClyjMessagePushService;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletRequest;
import javax.transaction.RollbackException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;

/**
 * <p>
 * 平台管理---消息推送 前端控制器
 * </p>
 *
 * @author kh
 * @since 2019-05-08
 */
@Controller
@RequestMapping("/clyjMessagePush")
public class ClyjMessagePushController {

	@Autowired
	private ClyjMessagePushService  clyjMessagePushService;
    
    /**
     * 推送  消息推送
     *
     * @param clyjMessagePush
     * @return
     * @throws RollBackExecption 
     * @throws RollbackException 
     */
	@RequestMapping(value = "/messagePush")
    @ResponseBody
    public ApiResult<?> messagePush(ClyjMessagePush clyjMessagePush,ClyjMessagePushFormwordDesc pushDesc) throws RollBackExecption, RollbackException {
        if (clyjMessagePush.getState()!= null &&  clyjMessagePush.getState().equals("1")) {
            return this.clyjMessagePushService.saveMessagePush(clyjMessagePush,pushDesc);
        } else if(clyjMessagePush.getState()!= null &&  clyjMessagePush.getState().equals("0")) {
            return this.clyjMessagePushService.immediatelyPush(clyjMessagePush,pushDesc);
        }
		return ApiResult.fail("参数非法");
    }
    
    /**
     * 获取消息推送信息列表
     *
     * @param clyjMessagePush
     * @param pageHelper
     * @return
     */
    @ApiOperation(value = "获取消息推送信息列表")
    @RequestMapping(value = "/messagePushList")
    @ResponseBody
    public PageTableResponse messagePushList(ClyjMessagePush clyjMessagePush, PageHelper pageHelper) {
        return this.clyjMessagePushService.messagePushList(clyjMessagePush, pageHelper);
    }
    /**
     * 根据id获取消息推送信息
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "根据id获取消息推送信息")
    @GetMapping("/{id}")
    @PreAuthorize("hasAuthority('messagepush:query')")
    @ResponseBody
    public ClyjMessagePush get(@PathVariable String id) {
    	ClyjMessagePush clyjMessagePush = clyjMessagePushService.selectById(id);
        return clyjMessagePush;
    }

    
    
}

